package com.powernode.ssm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 访问 http://localhost:8080/swagger-ui.html#/ 进入swagger接口文档
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                // 扫描的包路径，替换成你自己的 Controller 包名
                .apis(RequestHandlerSelectors.basePackage("com.powernode.ssm.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot + Swagger2 示例 API")
                .description("这是一个使用 Springfox Swagger2 构建的 RESTful API 文档")
                .version("1.0")
                .contact(new Contact("Ben",null,null))
                .build();
    }
}